package com.junmo.fanbizhidemo;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import com.jaeger.library.StatusBarUtil;
import com.junmo.fanbizhidemo.adapter.TabMainAdapter;
import com.junmo.fanbizhidemo.fragment.HomeFragment;
import com.junmo.fanbizhidemo.fragment.LoactionFragment;
import com.junmo.fanbizhidemo.fragment.SearchFragment;
import com.junmo.fanbizhidemo.fragment.SelectFragment;
import com.junmo.fanbizhidemo.fragment.SettingFragment;
import com.junmo.fanbizhidemo.view.MyBottomLayout;
import com.junmo.fanbizhidemo.view.TabViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends FragmentActivity {

    @BindView(R.id.myBottomLayout)
    MyBottomLayout myBottomLayout;
    @BindView(R.id.vp)
    TabViewPager viewpager;

    private List<Fragment> fragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        StatusBarUtil.setColor(MainActivity.this,getResources().getColor(R.color.colorPrimary),45);
        setWidget();
    }

    private void setWidget() {
        fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new LoactionFragment());
        fragments.add(new SearchFragment());
        fragments.add(new SelectFragment());
        fragments.add(new SettingFragment());

        List<String> strings = new ArrayList<>();
        strings.add("朵儿美");
        strings.add("科普");
        strings.add("健康圈");
        strings.add("健康圈");
        strings.add("个人");
        viewpager.setAdapter(new TabMainAdapter(getSupportFragmentManager(), fragments, strings));
        myBottomLayout.setonCallbackListener(new MyCallbackListener());
    }

    /**
     * 切换接口
     */
    private class MyCallbackListener implements MyBottomLayout.ICallbackListener {

        @Override
        public void clic(int id) {
            switch (id) {
                case R.id.homeLayout:
                    viewpager.setCurrentItem(0);
                    break;
                case R.id.selectLayout:
                    viewpager.setCurrentItem(1);
                    break;
                case R.id.searchLayout:
                    viewpager.setCurrentItem(2);
                    break;
                case R.id.locationLayout:
                    viewpager.setCurrentItem(3);
                    break;
                case R.id.settingLayout:
                    viewpager.setCurrentItem(4);
                    break;
            }
        }
    }

}
